<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>任务管理</el-breadcrumb-item>
      <el-breadcrumb-item>审核列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card shadow="always" :body-style="{ padding: '20px' }">
      <!-- 搜索 -->
      <el-input
        placeholder="请输入内容"
        class="input-with-select"
        v-model="queryInfo.query"
        clearable
        style="width: 30%; margin-bottom: 15px"
        @clear="getAuditList"
        @keyup.enter.native="handleSearch"
      >
        <el-button
          slot="append"
          type="primary"
          icon="el-icon-search"
          @click="getAuditList"
        ></el-button>
      </el-input>

      <!-- 状态 -->
      <div class="status">
        <el-radio-group v-model="queryInfo.status" @change="statusChange">
          <el-radio :label="0">进行中</el-radio>
          <el-radio :label="1">审核中</el-radio>
          <el-radio :label="2">被打回</el-radio>
          <el-radio :label="3">已完成</el-radio>
        </el-radio-group>
      </div>

      <!-- 展示表格 -->
      <el-table :data="AuditList" border>
        <el-table-column prop="taskname" label="任务名称"></el-table-column>
        <el-table-column prop="" label="提交时间">
          <template slot-scope="scope">
            <div>
              {{ scope.row.createdAt | date }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="" label="审核人">
           <template slot-scope="scope">
            <span>
              {{ scope.row.creator.name }}
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="提交人">
          <template slot-scope="scope">
            <span v-for="(item, index) in scope.row.worker" :key="index">
              {{ item.name }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="任务等级">
          <template slot-scope="scope">
            <div v-if="scope.row.grade === 0">顶级</div>
            <div v-if="scope.row.grade === 1">二级</div>
            <div v-if="scope.row.grade === 2">三级</div>
            <div v-if="scope.row.grade === 3">四级</div>
            <div v-if="scope.row.grade === 4">五级</div>
          </template>
        </el-table-column>
        <el-table-column prop="" label="状态">
          <template slot-scope="scope">
            <div
              v-if="scope.row.status == 0"
              style="color: #67c23a; font-weight: bold"
            >
              进行中
            </div>
            <div
              v-if="scope.row.status == 1"
              style="color: #67c23a; font-weight: bold"
            >
              审核中
            </div>
            <div
              v-if="scope.row.status == 2"
              style="color: #f56c6c; font-weight: bold"
            >
              被打回
            </div>
            <div
              v-if="scope.row.status == 3"
              style="color: #9093a5; font-weight: bold"
            >
              已完成
            </div>
          </template>
        </el-table-column>

        <el-table-column label="操作" width="150px">
          <template slot-scope="scope">
            <el-button
              type="success"
              size="mini"
              @click="$router.push(`/auditConfirm/${scope.row._id}`)"
              v-if="scope.row.status === 0 || scope.row.status === 2"
              >提交</el-button
            >
            <el-button
              type="warning"
              size="mini"
              v-if="scope.row.status === 1"
              @click="$router.push(`/auditConfirm/${scope.row._id}`)"
              >审核</el-button
            >
            <el-button
              type="primary"
              size="mini"
              @click="$router.push(`/auditConfirm/${scope.row._id}`)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination
        background
        layout="total, prev, pager, next"
        :total="total"
        style="margin-top: 20px"
        :current-page="queryInfo.pagenum"
        :page-size="queryInfo.pagesize"
        @current-change="handleCurrentChange"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import dayjs from "dayjs";
export default {
  filters: {
    date(val) {
      return dayjs(val).format("YYYY-MM-DD HH:mm:ss");
    },
  },
  data() {
    return {
      AuditList: [],
      queryInfo: {
        status: this.$route.query.status * 1 || 0,
        pagenum: this.$route.query.pagenum * 1 || 1, //第几页
        pagesize: 7, //每页显示个数
      },
      //总条数
      total: 0,
    };
  },
  methods: {
    //获取审核列表
    async getAuditList() {
      let res = await this.$http.get("/examine/getExamine", {
        params: this.queryInfo,
      });
      let data = res.data;
      if (data.status === 200) {
        this.AuditList = data.data.data;
        this.queryInfo.pagenum = data.data.pagenum;
        this.total = data.data.total;
      }
    },

    //页数改变触发事件
    handleCurrentChange(val) {
      this.queryInfo.pagenum = val;
      this.$router.replace({
        query: {
          status: this.$route.query.status,
          pagenum: val,
        },
      });
      this.getAuditList();
    },

    // 状态改变事件
    statusChange(val) {
      this.queryInfo.pagenum = 1;
      this.$router.replace({
        query: {
          status: val,
        },
      });
      this.getAuditList();
    },

    // 搜索Enter键盘事件
    handleSearch(val) {
      if (val.key == "Enter") {
        this.getAuditList();
      }
    },

    //打回
    // async handleDa(row) {
    //   this.$confirm(`是否打回 ${row.taskId.taskname} 任务`, "打回", {
    //     confirmButtonText: "确定",
    //     cancelButtonText: "取消",
    //     type: "warning",
    //   })
    //     .then(async () => {
    //       let res = await this.$http.put("/other/return", row);
    //       const data = res.data;
    //       //校验
    //       if (data.status === 401) return this.$message.error(data.msg);

    //       this.$message.success("打回成功");
    //       this.getAuditList();
    //     })
    //     .catch(() => {
    //       this.$message({
    //         type: "info",
    //         message: "已取消删除",
    //       });
    //     });
    // },
  },
  created() {
    this.getAuditList();
  },
};
</script>

<style lang="less" scoped>
// *{
//     font-weight: bold;
// }
.status {
  margin-bottom: 15px;
}
</style>